import Vue from 'vue'
import App from './App.vue'
import router from './router/index'
import utils from '@/utils/utils.js'
import api from './api/index'
import './style/base.scss'
import '@/filters/register-global'
import './components/register-global'
import '@/components/register-global'
import './element-ui'

Vue.config.productionTip = false
Vue.prototype.$utils = utils
Vue.prototype.$api = api

new Vue({
    data: {
        userInfo: null,
    },
    router,
    render: h => h(App),
    created() {
        this.getUserInfo()
    },
    methods: {
        async getUserInfo() {
            try {
                let {data} = await api.user.info()
                if (data.avatar && !data.avatar.includes('http://') && !data.avatar.includes('https://')) {
                    data.avatar = this.origin + data.avatar
                }
                utils.store.set('userInfo', data)
                this.userInfo = data
                return data
            } catch (e) {
                console.error(e)
                utils.store.remove('userInfo')
                this.userInfo = null
                return false
            }
        },
    }
}).$mount('#app')
